#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <signal.h>
#include <sys/time.h>
#include <fcntl.h>
#include <time.h>
#define _FILE_NAME_PORMAT_ "%s/linux_api_pro/local_api/daemon/log/mydaemon.%ld"
void dowork(int num)
{
        char *homeDir = getenv("HOME");
        char strFilename[250]= {0};
        sprintf(strFilename, _FILE_NAME_PORMAT_, homeDir,time(NULL) );
        int fd = open(strFilename, O_RDWR|O_CREAT,0666);
        if(fd < 0){
                perror("open err"); 
                return;
        }
        close(fd);
}
int main(int argc, char const *argv[])
{
        pid_t pid = fork();
        if(pid > 0){
                exit(1);
        }
        if(pid == 0){
                setsid();
                //chdir(getenv("HOME"));
                chdir("./");
                umask(0);
                close(STDIN_FILENO);
                close(STDOUT_FILENO);
                close(STDERR_FILENO);
                
                struct sigaction act;
                act.sa_flags = 0;
                act.sa_handler = dowork;
                sigemptyset(&act.sa_mask);
                sigaction(SIGALRM, &act, NULL);

                struct itimerval myit = {{10, 0},{10, 0}};
                setitimer(ITIMER_REAL, &myit, NULL);    
                while (1);    
        }
        return 0;
}
